package Demo_02;

/**
 * 单线程   懒汉模式
 */
public class Singleton_01 {
    private static Singleton_01 instance = null;
    private Singleton_01() {
    }
    public static Singleton_01 getInstance() {
        if(instance == null) {
            instance = new Singleton_01();
        }
        return instance;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            Thread thread = new Thread(() -> {
                //让全部线程进入if判断
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Singleton_01 instance = Singleton_01.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
}
